package cn.com.zhuxulin.info.Lists;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import cn.com.zhuxulin.info.Forms.Start;
import cn.com.zhuxulin.info.Forms.Weather;

public class CitiesList extends List {
	private Command ok;
	private String cityID;
	public CitiesList(String proName,String[] cities,final Display display,final Start start) {
		super(proName, List.IMPLICIT);
		ok=new Command("OK", Command.OK, 1);
		for(int i=0;i<cities.length&&null!=cities[i]&&!"".equals(cities[i]);i++){
			this.append(cities[i], null);
		}
		this.setSelectCommand(ok);
		this.setCommandListener(new CommandListener() {
			public void commandAction(Command cmd, Displayable dis) {
				cityID=getString(getSelectedIndex());
				cityID=cityID.substring(cityID.indexOf(",")+1);
				if(cmd==ok){
//					System.out.println("OK");
					display.setCurrent(new Weather(display, start, cityID));
				}
			}
		});
	}
}
